import 'package:flutter/material.dart';
import 'package:gobelieve/pages/chat_detail_page.dart';
import 'package:gobelieve/pages/index_page.dart';
import 'package:gobelieve/pages/loading.dart';

class Router {
  static final _routes = {
    '/': (BuildContext context, {Object args}) => LoadingPage(),
    '/app': (BuildContext context, {Object args}) => IndexPage(),
    '/chat_detail': (BuildContext context, {Object args}) =>
        ChatDetailPage(args: args),
  };

  static Router _singleton;

  Router._internal();

  factory Router() {
    if (_singleton == null) {
      _singleton = Router._internal();
    }

    return _singleton;
  }

  /// 监听route
  Route getRoutes(RouteSettings settings) {
    String routeName = settings.name;
    final Function builder = Router._routes[routeName];

    print(settings);

    if (builder == null) {
      return null;
    } else {
      return MaterialPageRoute(
          settings: settings,
          builder: (BuildContext context) =>
              builder(context, args: settings.arguments));
    }
  }
}
